{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .ck{
        display: block;height: 34px;padding: 6px 12px;font-size: 14px;line-height: 1.42857143;color: #555;background-color: #fff;background-image: none;border: 1px solid #ccc;border-radius: 4px;"
    }
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">渠道：</label>
                <div class="formControls col-xs-8 col-sm-8 col-md-8">
                    <select class="ck col-sm-2 col-md-3" size="1px" name="channel_id" >
                        <option value="" selected="selected">请选择渠道</option>
                        {volist name='chanel' id='v'}
                        <option value="{$v.id}">{$v.title}</option>
                        {/volist}
                    </select>
                </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">问题：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <select  class="col-xs-8 col-sm-2 goods_category ck" name="pro_id"  >
                    <option selected="selected" value="">请选择</option>
                    {volist name='go' id='v'}
                    <option value="{$v.id}">{$v.title}</option>
                    {/volist}</select>

                <select  class="col-xs-8 col-sm-2 goods ck" name="pro_id1"  >
                    <option selected="selected">请选择</option>
                </select>

                <select  class="col-xs-11 col-sm-2 good ck" name="pro_id2"  >
                    <option selected="selected">请选择</option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">时间：</label>
            <div class='input-group date col-xs-7 col-sm-3 col-md-3' id='datetimepicker2' style="padding-left: 18px">
                <input type='text' class="form-control" name="created_time" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>



        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">地址：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
				<select name="province" class="province col-xs-7 col-sm-2 ck"  ><option selected="selected">请选择地址</option></select>
                <select name="city" class="city col-xs-7 col-sm-3 ck" ><option selected="selected">请选择地址</option></select>
                <select name="area" class="area col-xs-7 col-sm-3 ck" ><option selected="selected">请选择地址</option></select>
                    <input type="text" class="col-xs-7 col-sm-2 ck"  name="addres" placeholder="请输入详细地址" >
            </div>

        </div>
        <div class="row cl">
            <label class="form-label  col-xs-3 col-sm-2 col-md-2">联系人：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <input type="text" class="col-sm-2 col-md-3 ck"   value="" name="contacts"  placeholder="请输入联系人">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">联系电话:</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <input type="text" class="col-sm-2 col-md-3 ck" value="" name="telephone"  placeholder="请输入联系人电话">
            </div>
        </div>
	 <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">小区名称:</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <input type="text" class="col-sm-2 col-md-3 ck" value="" name="residential_quarters"  placeholder="请输入小区名称">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">是否有效:</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <select class="ck col-sm-2 col-md-2" size="1px" name="state" >
                    <option value="0" selected="selected">有效</option>
                    <option value="10">无效</option>

                </select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2" >订单状态:</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <select  class=" remotes col-xs-8 col-sm-3 ck"
                        name="status" >
                    <option selected="selected" value="">请选择</option>
                    {volist name='remote' id='v'}
                    <option value="{$v.id}">{$v.title}</option>
                    {/volist}</select>
                </select>

                <select  class=" goo col-xs-8 col-sm-3 ck"
                        name="status1" >
                    <option selected="selected">请选择</option>
                </select>

                <select  class=" remote col-xs-8 col-sm-3 ck"
                        name="status2" >
                    <option selected="selected">请选择</option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">跟进时间:</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <input type="text" name="start_time" id="countTimestart" onfocus="selecttime(1)" size="17"
                       class="date col-sm-5 col-md-6 ck" readonly
                       value="<?php echo date('Y-m-d H:i:s',time())?>" >
            </div>

        </div>
	 <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">所属物业：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <select class="ck col-sm-2 col-md-3" size="1px" name="residential_id" >
                    <option value="" selected="selected">请选择所属物业</option>
                    {volist name='title' id='v'}
                    <option value="{$v.residential_id}">{$v.content}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">推荐人：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <input type="text" class="col-sm-2 col-md-3 ck" value="" name="management"  placeholder="请输入推荐人">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2">备注：</label>
            <div class="formControls col-xs-8 col-sm-8">
                    <textarea placeholder="请输入备注"  name="remarks" class="ck col-sm-5 col-md-6"></textarea>
                <!--<input type="text" class="form-control" value="" name="remarks" style="width: 50%" placeholder="请输入备注">-->
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2 col-md-2"><span class="c-red">*</span>图片：</label>
            <div class="formControls col-xs-8 col-sm-8 col-md-8">
                <div id="uploader-demo">
                    <!--用来存放item-->
                    <div id="filePicker">选择图片</div>
                    <div id="fileList" class="uploader-list">

                    </div>
                </div>

            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
                <a class="btn btn-warning" style="line-height:1.6em;margin-top:3px" href="{:url('index/order/index')}?type=0;" >返回</a>
            </div>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>

    $('.remotes').bind("change", function () {
        //向input输入框中赋值
        goo();
    });
    $(".goo").bind("change", function () {
        remote()
    });
    function goo() //市
    {
        var parent_ids = $(".remotes option:selected").val();
        if(parent_ids==''){
            alert('请选择订单状态')
        }
        $.post("{:url('index/order/remote')}", {parent_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }

            $('.goo').html(html);
            remote();


        });


    }


    function remote() {
        var parent_id = $('.goo').val();
        var html;

        if (parent_id) {
            $.post("{:url('index/order/remote')}", {parent_id: parent_id}, function (data, textStatus, xhr) {

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";

                    }
                } else {
                    html += "<option value=''>暂无数据</option>";
                }

                $('.remote').html(html);

            });
        } else {
            html += "<option value=''>暂无数据</option>";
            $('.remote').html(html);
        }

    }
    $('.goods_category').bind("change", function () {
        //向input输入框中赋值
        goods();
    });
    $(".goods").bind("change", function () {
        good()
    });


    function goods() //市
    {
        var parent_ids = $(".goods_category option:selected").val();
        $.post("{:url('index/order/goods_category')}", {parent_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }

            $('.goods').html(html);
            good();


        });
    }


    function good() {
        var parent_id = $('.goods').val();
        var html;

        if (parent_id) {
            $.post("{:url('index/order/goods_category')}", {parent_id: parent_id}, function (data, textStatus, xhr) {

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";

                    }
                } else {
                    html += "<option value=''>暂无数据</option>";
                }

                $('.good').html(html);

            });
        } else {
            html += "<option value=''>暂无数据</option>";
            $('.good').html(html);
        }

    }
        privance();


    $('.radius').click(function () {
        var src="{:Url('index/order/add')}";
	 $(this).attr('disabled',true);
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data:$('form').serializeArray(),
            success: function (data) {
                var res=JSON.parse(data);
		 $('.radius').attr("disabled",false);
                if(res.code==200){
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index,layero) {
                        window.location.assign("{:url('index/order/index')}?type=0")
                    });
                }else{
                    layer.msg(res.msg,{icon: 5,time:1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    function goods_category() //省
    {
        $.post("{:url('index/order/goods_category')}", {parent_id: '0',}, function(data, textStatus, xhr) {
            var html;
            html+="<option selected='selected'>请选择问题</option>";
            for (var i = 0; i<data.length; i++) {
                html += "<option value='"+data[i]['id']+"'>"+data[i]['title']+"</option>";
            }

            $('.goods_category').html(html);

        });
    }
    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object){
        $(object).parent().remove();
        count-=1;
    }
    var count=1;
    $(function(){
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate:true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                    '<div id="' + file.id + '" class="file-item thumbnail">' +
                    '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>'+
                    '<img style="width: 100px;height: 100px;">' +
                    '<input name="logo[]" type="hidden" value="">'+
                    '<div class="info">' + file.name + '</div>' +
                    '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, 100, 100 );
        });



        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
            }


            $percent.css( 'width', percentage * 100 + '%' );
        });
    var s=[];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,res ) {
            var data = JSON.parse(res._raw);
            if(data.errcode==300){
                layer.alert(data.msg);
            }
            var url = data.data;
            count+=1;
            $( '#'+file.id).find("logo").attr("src",url);
            $( '#'+file.id).find("input").val(url);
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });

    function selecttime(flag) {
        if (flag == 1) {
            var endTime = $("#countTimeend").val();
            if (endTime != "") {
                WdatePicker({dateFmt: 'yyyy-MM-dd H:m:s', maxDate: endTime})
            } else {
                WdatePicker({dateFmt: 'yyyy-MM-dd H:m:s'})
            }
        } else {
            var startTime = $("#countTimestart").val();
            if (startTime != "") {
                WdatePicker({dateFmt: 'yyyy-MM-dd H:m:s', minDate: startTime})
            } else {
                WdatePicker({dateFmt: 'yyyy-MM-dd H:m:s'})
            }
        }
    }

</script>
</body>
</html>
